package com.maila.xiaoaoschool.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.maila.xiaoaoschool.R;
import com.maila.xiaoaoschool.adapter.SchoolSelectAdapter;
import com.maila.xiaoaoschool.api.IndexApi;
import com.maila.xiaoaoschool.api.LoginApi;
import com.maila.xiaoaoschool.entity.SchoolLocation;
import com.maila.xiaoaoschool.net.VolleyInterface;
import com.maila.xiaoaoschool.widget.SideBar;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 定位
 * Created by Administrator on 2017/11/1.
 */

public class LocationActivity extends AppCompatActivity {
    @BindView(R.id.white_return_iv)
    AutoRelativeLayout whiteReturnIv;
    @BindView(R.id.lv_loction_schools)
    ListView lvLoctionSchools;
    @BindView(R.id.ll_location)
    AutoLinearLayout llLocation;
    @BindView(R.id.lv_all_schools)
    ListView lvAllSchools;
    @BindView(R.id.dialog)
    TextView dialog;
    @BindView(R.id.contents)
    FrameLayout contents;
    @BindView(R.id.sidrbar)
    SideBar sidrbar;
    SchoolSelectAdapter selectAdapter;
    SchoolSelectAdapter locationAdapter;
    Gson gson=new Gson();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_location);
        ButterKnife.bind(this);
        selectAdapter=new SchoolSelectAdapter(this);
        locationAdapter=new SchoolSelectAdapter(this);
        lvLoctionSchools.setAdapter(locationAdapter);
        lvAllSchools.setAdapter(selectAdapter);
        initdata();
    }

    private void initdata() {
        new IndexApi(this, new VolleyInterface() {
            @Override
            public void onSuccess(String result) {
                SchoolLocation schoolLocation=gson.fromJson(result,SchoolLocation.class);
                if(schoolLocation.getResult()==1){
                    selectAdapter.setMdata(schoolLocation.getData());
                }else {

                }
            }

            @Override
            public void onError(VolleyError error) {

            }
        }).getSchoollist();
    }

    @OnClick(R.id.white_return_iv)
    public void onViewClicked() {
        finish();
    }
}